﻿Imports Microsoft.VisualBasic

Namespace My
    Public Class CodeMappingSqlDataSource
        Inherits MySqlDataSource

        Private Sub CodeMappingSqlDataSource_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            Dim sql As New StringBuilder

            sql.AppendFormat("SELECT Value, Text={0} ", Me.TextColumnName)
            sql.AppendFormat(" FROM GetCodeMappingData(@TableName, @ColumnName) ")
            sql.AppendFormat("where Active = 'Y' ")
            sql.AppendFormat("order by Sequence ")

            Me.SelectCommand = sql.ToString()

            Me.SelectParameters.Add("TableName", Me.TableName)
            Me.SelectParameters.Add("ColumnName", Me.ColumnName)
        End Sub

        Private Sub CodeMappingSqlDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles Me.Selecting
            'Me.SelectParameters("").DefaultValue = Me.TableName
            'e.Command.Parameters(.SelectParameters.Add("TableName", Me.TableName)
            'Me.SelectParameters.Add("ColumnName", Me.ColumnName)

        End Sub

        Public Property TableName() As String
            Get
                Return ViewState("TableName")
            End Get
            Set(ByVal value As String)
                ViewState("TableName") = value
            End Set
        End Property

        Public Property ColumnName() As String
            Get
                Return ViewState("ColumnName")
            End Get
            Set(ByVal value As String)
                ViewState("ColumnName") = value
            End Set
        End Property

        Public Property TextColumnName() As String
            Get
                If ViewState("TextColumnName") Is Nothing Then
                    ViewState("TextColumnName") = "Text"
                End If
                Return ViewState("TextColumnName")
            End Get
            Set(ByVal value As String)
                ViewState("TextColumnName") = value
            End Set
        End Property
    End Class
End Namespace
